package com.github.sub.user;

import com.github.Common;

import java.io.File;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;

import static com.github.MyAutoTestContext.CURRENT_PATH;
import static com.github.MyAutoTestContext.PATH;

public class UserCurrentCommander extends Common implements com.github.Commander {

    @Override
    public Object run(Map<String, String> command) {
        String value = command.get("-cur");
        String currentPath = currentPath();
        String[] list = tradition.list(user);
        Optional<String> first = Arrays.stream(list).filter(n -> n.equals(value)).findFirst();
        if (first.isPresent()) {
            String read = read(new File(user + value));
            tradition.outPutFile((value + "=" + read).getBytes(), currentPath + PATH + CURRENT_PATH, userCurrent);
            System.out.println("user  current  is " + value);
        } else {
            System.out.println("env current    " + value + " path is not exits");
        }
        return null;
    }
}
